﻿<!DOCTYPE HTML>
<html th:with="title='商品管理'">
<head th:include="fragments/header :: header">
<meta charset="utf-8" />
</head>
<body id="app">
	<div class="page-container">
		<div class="cl pd-5 bg-1 bk-gray">
			<span class="r">
				<a class="btn btn-success size-S radius" href="javascript:location.replace(location.href);" title="刷新">
					<i class="Hui-iconfont">&#xe68f;</i>
					刷新
				</a>
			</span>
		</div>
		<div class="text-l pd-5">
			云科号：
			<input type="text" class="input-text size-S" th:value="${user.outSn}" style="width: 150px" placeholder="请输入云科号" id="yunkeNum" name="yunkeNum">
			<button type="button" class="btn btn-success size-S radius" onclick="query()">
				<i class="Hui-iconfont">&#xe665;</i>
				查询云科商品
			</button>
		</div>
		<div>
			<table class="table table-border table-bordered table-hover table-bg table-sort">
				<thead>
					<tr class="text-c">
						<th width="25">
							<input type="checkbox" name="" value="" />
						</th>
						<th width="100">商品状态</th>
						<th width="100">商品名称</th>
						<th width="100">商品价格</th>
						<th width="100">商品积分</th>
						<th width="100">商品缩略图</th>
						<th width="100">商品规格</th>
						<th width="100">商品分类</th>
						<th width="100">是否热卖</th>
					</tr>
				</thead>
				<tbody>
					<tr class="text-c" v-for="item in pageData.rows">
						<td>
							<input type="checkbox" value="{{ item.goodsid }}" name="ids">
						</td>
						<input type="hidden" value="{{ item.introduction }}" id="introduction{{ item.goodsid }}">
						<input type="hidden" value="{{ item.slideImage }}" id="slideImage{{ item.goodsid }}">
						<td class="text-l">
							<input type="hidden" value="{{ item.isexit }}" id="isexit{{ item.goodsid }}">
							{{ item.isexit|productImportStatusFilter }}
						</td>
						<td>
							<input type="hidden" value="{{ item.name }}" id="name{{ item.goodsid }}">
							{{ item.name }}
						</td>
						<td>
							<input type="hidden" value="{{ item.price }}" id="price{{ item.goodsid }}">
							{{ item.price }}
						</td>
						<td>
							<input type="hidden" value="{{ item.rewardPoint }}" id="rewardPoint{{ item.goodsid }}">
							{{ item.rewardPoint }}
						</td>
						<td>
							<input type="hidden" value="{{ item.image }}" id="image{{ item.goodsid }}">
							<a href="{{ item.image }}" target="_blank">
								<img src="{{ item.image }}" style="height: 50px" />
							</a>
						</td>
						<td>
							<input type="hidden" value="{{ item.specificationList }}" id="specificationList{{ item.goodsid }}">
							{{ item.specificationList }}
						</td>
						<td>
							<input type="hidden" value="{{ item.categoryName }}" id="categoryName{{ item.goodsid }}">
							<input type="hidden" value="{{ item.categoryId }}" id="categoryId{{ item.goodsid }}">
							{{ item.categoryName }}
						</td>
						<td>
							<input type="hidden" value="{{ item.ishot }}" id="ishot{{ item.goodsid }}">
							{{ item.ishot | ishot }}
						</td>
					</tr>
				</tbody>
			</table>

			<div v-show="pageData.total > 0" class="laypage_main laypageskin_default" style="margin-top: 10px">
				<div class="l">
					<span>
						每页
						<select name="pageSizeSelect" id="pageSizeSelect" style="vertical-align: baseline !important; height: 27.6px;" onchange="query()">
							<option value="10" selected="selected">10</option>
							<option value="25">25</option>
							<option value="50">50</option>
							<option value="100">100</option>
						</select>
						条 显示 {{pageData.rowIndexStart}} 到 {{pageData.rowIndexEnd}} ，共 {{pageData.total}} 条
					</span>
				</div>
				<div id="pageNav" class="r"></div>
			</div>
		</div>

	</div>
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary size-L radius" type="button" onclick="test()" value="提交">
			<input class="btn btn-primary size-L radius" type="button" onclick="closeWin()" value="关闭">
		</div>
	</div>
	<script type="text/javascript">
		// ==================================================
		var app = new Vue({
			el : '#app',
			data : {
				pageData : {}
			}
		});

		/*
		 * 查询所有云科商品
		 */
		function query(pageNo, pageSize) {
			if (!pageNo) {
				pageNo = 1;
			}
			if (!pageSize) {
				pageSize = $("#pageSizeSelect").val();
			}
			var tip = layer.load(0, {
				shade : false
			});
			$.ajax({
				type : "POST",
				url : '/manager/product/searchYKProduct',
				data : {
					pageNo : pageNo,
					pageSize : pageSize,
					yunkeNum : $("#yunkeNum").val()
				},
				beforeSend : function() {
				},
				complete : function() {
					layer.close(tip);
				},
				error : function(request) {
					layer.alert("系统错误");
				},
				success : function(result) {
					if (result.status == 0) {
						var data = result.data;
						app.pageData = data;
						laypage({
							cont : 'pageNav',
							pages : data.totalPage,
							curr : data.currentPage,
							skip : true,
							groups : 6,
							jump : function(obj, first) {
								if (!first) {
									query(obj.curr);
								}
							}
						});
					} else {
						sessionCheckTimeOut(result);
					}
				}
			});
		}

		/*
		 * 商品同步
		 */
		function importP(prodataList) {
			var tip = layer.load(0, {
				shade : false
			});
			$.ajax({
				type : "POST",
				url : '/manager/product/importProduct',
				data : {
					"product" : JSON.stringify(prodataList)
				},
				beforeSend : function() {
				},
				complete : function() {
					layer.close(tip);
				},
				error : function(request) {
					layer.alert("系统错误");
				},
				success : function(data) {
					if (data.status == 0) {
						refreshUParentList();
						layer.alert(data.message, function() {
							var index = parent.layer.getFrameIndex(window.name);
							parent.layer.close(index);
						});
					} else {
						layer.alert(data.message);
					}
				}
			});
		}
		function test() {
			var prodataList = [];
			var selectdItems = $(":checkbox[name=ids]:checked");
			if (selectdItems.size() == 0) {
				layer.alert("请选择要导入的商品！");
				return;
			}
			selectdItems.each(function() {
				prodataList.push(getP($(this).val()));
			});
			importP(prodataList);
		}

		function getP(goodsid) {
			var pro = {
				"introduction" : $("#introduction" + goodsid).val(),
				"slideImage" : $("#slideImage" + goodsid).val(),
				"goodsid" : goodsid,
				"name" : $("#name" + goodsid).val(),
				"rewardPoint" : $("#rewardPoint" + goodsid).val(),
				"image" : $("#image" + goodsid).val(),
				"specificationList" : $("#specificationList" + goodsid).val(),
				"price" : $("#price" + goodsid).val(),
				"categoryId" : $("#categoryId" +goodsid).val(),
				"categoryName" : $("#categoryName" +goodsid).val(),
			}
			return pro;
		}
		$(function() {
			//query();
		});
	</script>
</body>
</html>